package databaseVersionControl.domain.factory.composite;

import databaseVersionControl.domain.db.Column;
import databaseVersionControl.domain.db.Table;
import databaseVersionControl.domain.db.TableComponent;
import databaseVersionControl.domain.ddl.CreateComposite;
import databaseVersionControl.infra.script.validation.CheckExistTablePreInstallCondition;

public class CreateTableComposite extends CreateComposite<Table> implements TableComponent {

	private CheckExistTablePreInstallCondition preInstallCondition = null;

	public CreateTableComposite(Table table) {
		super(table);
	}

	public CreateTableComposite defineColumns(Column... columns) {
		component.defineColumns(columns);		
		return this;
	}

	@Override
	public String getName() {
		return component.getName();
	}

	@Override
	public CreateTableComposite addColumn(Column column) {
		component.addColumn(column);
		return this;
	}

	@Override
	public CreateTableComposite ifNotExists() {
		preInstallCondition = new CheckExistTablePreInstallCondition(this);
		return this;
	}

	@Override
	public CreateComposite<Table> revokeIfNotExists() {
		preInstallCondition = null;
		return this;
	}

	@Override
	public boolean hasPreInstallCondition() {
		return getPreInstallCondition() != null;
	}

	@Override
	public CheckExistTablePreInstallCondition getPreInstallCondition() {
		return preInstallCondition;
	}

	

}
